        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>Island class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="Island">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/Island.html">Island</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>Island</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class Island {
 ContactListener listener;

 List&lt;Body&gt; bodies;
 List&lt;Contact&gt; contacts;
 List&lt;Joint&gt; joints;

 List&lt;Position&gt; positions;
 List&lt;Velocity&gt; velocities;

 int bodyCount;
 int jointCount;
 int contactCount;

 int bodyCapacity;
 int contactCapacity;
 int jointCapacity;

 int positionIterationCount;

 // Pool objects to cut down on object creation.
 ContactSolver _contactSolver;
 vec2 _translation;
 ContactImpulse impulse;

 Island() :
   _contactSolver = new ContactSolver(),
   _translation = new vec2.zero(),
   impulse = new ContactImpulse() { }

 //TODO(gregbglw): No need to keep capacity, count and array for these items as
 // in C. Simply measure the length of the array, for example, in order to
 // determine capacity.
 void init(int argBodyCapacity, int argContactCapacity, int argJointCapacity,
     ContactListener argListener) {
   bodyCapacity = argBodyCapacity;
   contactCapacity = argContactCapacity;
   jointCapacity = argJointCapacity;
   bodyCount = 0;
   contactCount = 0;

   listener = argListener;

   if (bodies == null || bodyCapacity &gt; bodies.length) {
     bodies = new List&lt;Body&gt;(bodyCapacity);
   }
   if (contacts == null || contactCapacity &gt; contacts.length) {
     contacts = new List&lt;Contact&gt;(contactCapacity);
   }
   if (joints == null || jointCapacity &gt; joints.length) {
     joints = new List&lt;Joint&gt;(jointCapacity);
   }

   // dynamic array
   if (velocities == null || bodyCapacity &gt; velocities.length) {
     final List&lt;Velocity&gt; old = velocities == null ?
         new List&lt;Velocity&gt;(0) : velocities;
     velocities = new List&lt;Velocity&gt;(bodyCapacity);
     velocities.setRange(0, old.length, old);
     for (int i=old.length; i&lt;velocities.length; i++) {
       velocities[i] = new Velocity();
     }
   }

   // dynamic array
   if(positions == null || bodyCapacity &gt; positions.length){
     List&lt;Position&gt; old = positions == null ?
         new List&lt;Position&gt;(0) : positions;
     positions = new List&lt;Position&gt;(bodyCapacity);
     positions.setRange(0, old.length, old);
     for (int i=old.length; i&lt;positions.length; i++) {
       positions[i] = new Position();
     }
   }
 }

 void clear() {
   bodyCount = 0;
   contactCount = 0;
   jointCount = 0;
 }

 void solve(TimeStep time_step, vec2 gravity, bool allowSleep){
   // Integrate velocities and apply damping.
   for (int i = 0; i &lt; bodyCount; ++i){
     Body b = bodies[i];

     if (b.type != BodyType.DYNAMIC){
       continue;
     }

     final velocityDelta = new vec2(
         (b._force.x * b.invMass + gravity.x) * time_step.dt,
         (b._force.y * b.invMass + gravity.y) * time_step.dt);
     b.linearVelocity.add(velocityDelta);
     num newAngularVelocity = b.angularVelocity +
         (time_step.dt * b.invInertia * b._torque);
     b.angularVelocity = newAngularVelocity;

     num a = (1.0 - time_step.dt * b.linearDamping);
     num a1 = (0.0 &gt; (a &lt; 1.0 ? a : 1.0) ? 0.0 : (a &lt; 1.0 ? a : 1.0));
     b.linearVelocity.scale(a1);

     num a2 = (1.0 - time_step.dt * b.angularDamping);
     num b1 = (a2 &lt; 1.0 ? a2 : 1.0);
     b.angularVelocity *= 0.0 &gt; b1 ? 0.0 : b1;
   }

   // Partition contacts so that contacts with static bodies are solved last.
   int i1 = -1;
   for (int i2 = 0; i2 &lt; contactCount; ++i2) {
     Fixture fixtureA = contacts[i2].fixtureA;
     Fixture fixtureB = contacts[i2].fixtureB;
     Body bodyA = fixtureA.body;
     Body bodyB = fixtureB.body;
     bool nonStatic = bodyA.type != BodyType.STATIC &amp;&amp; bodyB.type
         != BodyType.STATIC;
     if (nonStatic){
       ++i1;
       //Swap(contacts[i1], contacts[i2]);
       Contact temp = contacts[i1];
       contacts[i1] = contacts[i2];
       contacts[i2] = temp;
     }
   }

   // Initialize velocity constraints.
   _contactSolver.init(contacts, contactCount, time_step.dtRatio);
   _contactSolver.warmStart();

   for (int i = 0; i &lt; jointCount; ++i){
     joints[i].initVelocityConstraints(time_step);
   }

   for (int i = 0; i &lt; time_step.velocityIterations; ++i) {
     for (int j = 0; j &lt; jointCount; ++j){
       joints[j].solveVelocityConstraints(time_step);
     }
     _contactSolver.solveVelocityConstraints();
   }

   // Post-solve (store impulses for warm starting).
   _contactSolver.storeImpulses();

   // Integrate positions.
   vec2 temp = new vec2.zero();
   for (int i = 0; i &lt; bodyCount; ++i){
     Body b = bodies[i];

     if (b.type == BodyType.STATIC){
       continue;
     }

     // Check for large velocities.
     _translation.copyFrom(b.linearVelocity).scale(time_step.dt);
     if (dot(_translation, _translation) &gt; Settings.MAX_TRANSLATION_SQUARED) {
       num ratio = Settings.MAX_TRANSLATION / _translation.length;
       b.linearVelocity.scale(ratio);
     }

     num rotation = time_step.dt * b.angularVelocity;
     if (rotation * rotation &gt; Settings.MAX_ROTATION_SQUARED) {
       num ratio = Settings.MAX_ROTATION / rotation.abs();
       b.angularVelocity *= ratio;
     }

     // Store positions for continuous collision.
     b.sweep.centerZero.copyFrom(b.sweep.center);
     b.sweep.angleZero = b.sweep.angle;

     // Integrate
     temp.copyFrom(b.linearVelocity).scale(time_step.dt);
     b.sweep.center.add(temp);
     b.sweep.angle += time_step.dt * b.angularVelocity;

     // Compute new transform
     b.synchronizeTransform();

     // Note: shapes are synchronized later.
   }

   // Iterate over constraints.
   for (int i = 0; i &lt; time_step.positionIterations; ++i){
     bool contactsOkay =
         _contactSolver.solvePositionConstraints(Settings.CONTACT_BAUMGARTE);

     bool jointsOkay = true;
     for (int j = 0; j &lt; jointCount; ++j){
       bool jointOkay =
           joints[j].solvePositionConstraints(Settings.CONTACT_BAUMGARTE);
       jointsOkay = jointsOkay &amp;&amp; jointOkay;
     }

     if (contactsOkay &amp;&amp; jointsOkay){
       // Exit early if the position errors are small.
       break;
     }
   }

   report(_contactSolver.constraints);


   if (allowSleep){
     num minSleepTime = Settings.BIG_NUMBER;

     num linTolSqr = Settings.LINEAR_SLEEP_TOLERANCE
         * Settings.LINEAR_SLEEP_TOLERANCE;
     num angTolSqr = Settings.ANGULAR_SLEEP_TOLERANCE
         * Settings.ANGULAR_SLEEP_TOLERANCE;

     for (int i = 0; i &lt; bodyCount; ++i){
       Body b = bodies[i];
       if (b.type == BodyType.STATIC){
         continue;
       }

       if ((b.flags &amp; Body.AUTO_SLEEP_FLAG) == 0){
         b.sleepTime = 0.0;
         minSleepTime = 0.0;
       }

       if ((b.flags &amp; Body.AUTO_SLEEP_FLAG) == 0 ||
           b.angularVelocity * b.angularVelocity &gt; angTolSqr ||
           dot(b.linearVelocity, b.linearVelocity) &gt; linTolSqr) {
         b.sleepTime = 0.0;
         minSleepTime = 0.0;
       }
       else{
         b.sleepTime += time_step.dt;
         minSleepTime = math.min(minSleepTime, b.sleepTime);
       }
     }

     if (minSleepTime &gt;= Settings.TIME_TO_SLEEP){
       for (int i = 0; i &lt; bodyCount; ++i){
         Body b = bodies[i];
         b.awake = false;
       }
     }
   }

 }

 /** Adds a body to the Island. */
 void addBody(Body body){
   assert(bodyCount &lt; bodyCapacity);
   body.islandIndex = bodyCount;
   bodies[bodyCount++] = body;
 }

 /** Add a contact to the Island. */
 void addContact(Contact contact) {
   assert(contactCount &lt; contactCapacity);
   contacts[contactCount++] = contact;
 }

 /** Add a joint to the Island. */
 void addJoint(Joint joint) {
   assert(jointCount &lt; jointCapacity);
   joints[jointCount++] = joint;
 }

 void report(List&lt;ContactConstraint&gt; constraints){
   if (listener == null){
     return;
   }

   for (int i = 0; i &lt; contactCount; ++i){
     Contact c = contacts[i];

     ContactConstraint cc = constraints[i];

     for (int j = 0; j &lt; cc.pointCount; ++j){
       impulse.normalImpulses[j] = cc.points[j].normalImpulse;
       impulse.tangentImpulses[j] = cc.points[j].tangentImpulse;
     }

     listener.postSolve(c, impulse);
   }
 }
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="Island">
<button class="show-code">Code</button>
new <strong>Island</strong>() <a class="anchor-link" href="#Island"
              title="Permalink to Island.Island">#</a></h4>
<div class="doc">
<pre class="source">
Island() :
 _contactSolver = new ContactSolver(),
 _translation = new vec2.zero(),
 impulse = new ContactImpulse() { }
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="bodies">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/Body.html">Body</a>&gt;         <strong>bodies</strong> <a class="anchor-link"
            href="#bodies"
            title="Permalink to Island.bodies">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bodies
</pre>
</div>
</div>
<div class="field"><h4 id="bodyCapacity">
<button class="show-code">Code</button>
int         <strong>bodyCapacity</strong> <a class="anchor-link"
            href="#bodyCapacity"
            title="Permalink to Island.bodyCapacity">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bodyCapacity
</pre>
</div>
</div>
<div class="field"><h4 id="bodyCount">
<button class="show-code">Code</button>
int         <strong>bodyCount</strong> <a class="anchor-link"
            href="#bodyCount"
            title="Permalink to Island.bodyCount">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bodyCount
</pre>
</div>
</div>
<div class="field"><h4 id="contactCapacity">
<button class="show-code">Code</button>
int         <strong>contactCapacity</strong> <a class="anchor-link"
            href="#contactCapacity"
            title="Permalink to Island.contactCapacity">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contactCapacity
</pre>
</div>
</div>
<div class="field"><h4 id="contactCount">
<button class="show-code">Code</button>
int         <strong>contactCount</strong> <a class="anchor-link"
            href="#contactCount"
            title="Permalink to Island.contactCount">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contactCount
</pre>
</div>
</div>
<div class="field"><h4 id="contacts">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/Contact.html">Contact</a>&gt;         <strong>contacts</strong> <a class="anchor-link"
            href="#contacts"
            title="Permalink to Island.contacts">#</a>
        </h4>
        <div class="doc">
<pre class="source">
contacts
</pre>
</div>
</div>
<div class="field"><h4 id="impulse">
<button class="show-code">Code</button>
<a href="../box2d/ContactImpulse.html">ContactImpulse</a>         <strong>impulse</strong> <a class="anchor-link"
            href="#impulse"
            title="Permalink to Island.impulse">#</a>
        </h4>
        <div class="doc">
<pre class="source">
impulse
</pre>
</div>
</div>
<div class="field"><h4 id="jointCapacity">
<button class="show-code">Code</button>
int         <strong>jointCapacity</strong> <a class="anchor-link"
            href="#jointCapacity"
            title="Permalink to Island.jointCapacity">#</a>
        </h4>
        <div class="doc">
<pre class="source">
jointCapacity
</pre>
</div>
</div>
<div class="field"><h4 id="jointCount">
<button class="show-code">Code</button>
int         <strong>jointCount</strong> <a class="anchor-link"
            href="#jointCount"
            title="Permalink to Island.jointCount">#</a>
        </h4>
        <div class="doc">
<pre class="source">
jointCount
</pre>
</div>
</div>
<div class="field"><h4 id="joints">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/Joint.html">Joint</a>&gt;         <strong>joints</strong> <a class="anchor-link"
            href="#joints"
            title="Permalink to Island.joints">#</a>
        </h4>
        <div class="doc">
<pre class="source">
joints
</pre>
</div>
</div>
<div class="field"><h4 id="listener">
<button class="show-code">Code</button>
<a href="../box2d/ContactListener.html">ContactListener</a>         <strong>listener</strong> <a class="anchor-link"
            href="#listener"
            title="Permalink to Island.listener">#</a>
        </h4>
        <div class="doc">
<pre class="source">
listener
</pre>
</div>
</div>
<div class="field"><h4 id="positionIterationCount">
<button class="show-code">Code</button>
int         <strong>positionIterationCount</strong> <a class="anchor-link"
            href="#positionIterationCount"
            title="Permalink to Island.positionIterationCount">#</a>
        </h4>
        <div class="doc">
<pre class="source">
positionIterationCount
</pre>
</div>
</div>
<div class="field"><h4 id="positions">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/Position.html">Position</a>&gt;         <strong>positions</strong> <a class="anchor-link"
            href="#positions"
            title="Permalink to Island.positions">#</a>
        </h4>
        <div class="doc">
<pre class="source">
positions
</pre>
</div>
</div>
<div class="field"><h4 id="velocities">
<button class="show-code">Code</button>
List&lt;<a href="../box2d/Velocity.html">Velocity</a>&gt;         <strong>velocities</strong> <a class="anchor-link"
            href="#velocities"
            title="Permalink to Island.velocities">#</a>
        </h4>
        <div class="doc">
<pre class="source">
velocities
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="addBody">
<button class="show-code">Code</button>
void <strong>addBody</strong>(<a href="../box2d/Body.html">Body</a> body) <a class="anchor-link" href="#addBody"
              title="Permalink to Island.addBody">#</a></h4>
<div class="doc">
<p>Adds a body to the Island. </p>
<pre class="source">
void addBody(Body body){
 assert(bodyCount &lt; bodyCapacity);
 body.islandIndex = bodyCount;
 bodies[bodyCount++] = body;
}
</pre>
</div>
</div>
<div class="method"><h4 id="addContact">
<button class="show-code">Code</button>
void <strong>addContact</strong>(<a href="../box2d/Contact.html">Contact</a> contact) <a class="anchor-link" href="#addContact"
              title="Permalink to Island.addContact">#</a></h4>
<div class="doc">
<p>Add a contact to the Island. </p>
<pre class="source">
void addContact(Contact contact) {
 assert(contactCount &lt; contactCapacity);
 contacts[contactCount++] = contact;
}
</pre>
</div>
</div>
<div class="method"><h4 id="addJoint">
<button class="show-code">Code</button>
void <strong>addJoint</strong>(<a href="../box2d/Joint.html">Joint</a> joint) <a class="anchor-link" href="#addJoint"
              title="Permalink to Island.addJoint">#</a></h4>
<div class="doc">
<p>Add a joint to the Island. </p>
<pre class="source">
void addJoint(Joint joint) {
 assert(jointCount &lt; jointCapacity);
 joints[jointCount++] = joint;
}
</pre>
</div>
</div>
<div class="method"><h4 id="clear">
<button class="show-code">Code</button>
void <strong>clear</strong>() <a class="anchor-link" href="#clear"
              title="Permalink to Island.clear">#</a></h4>
<div class="doc">
<pre class="source">
void clear() {
 bodyCount = 0;
 contactCount = 0;
 jointCount = 0;
}
</pre>
</div>
</div>
<div class="method"><h4 id="init">
<button class="show-code">Code</button>
void <strong>init</strong>(int argBodyCapacity, int argContactCapacity, int argJointCapacity, <a href="../box2d/ContactListener.html">ContactListener</a> argListener) <a class="anchor-link" href="#init"
              title="Permalink to Island.init">#</a></h4>
<div class="doc">
<pre class="source">
void init(int argBodyCapacity, int argContactCapacity, int argJointCapacity,
   ContactListener argListener) {
 bodyCapacity = argBodyCapacity;
 contactCapacity = argContactCapacity;
 jointCapacity = argJointCapacity;
 bodyCount = 0;
 contactCount = 0;

 listener = argListener;

 if (bodies == null || bodyCapacity &gt; bodies.length) {
   bodies = new List&lt;Body&gt;(bodyCapacity);
 }
 if (contacts == null || contactCapacity &gt; contacts.length) {
   contacts = new List&lt;Contact&gt;(contactCapacity);
 }
 if (joints == null || jointCapacity &gt; joints.length) {
   joints = new List&lt;Joint&gt;(jointCapacity);
 }

 // dynamic array
 if (velocities == null || bodyCapacity &gt; velocities.length) {
   final List&lt;Velocity&gt; old = velocities == null ?
       new List&lt;Velocity&gt;(0) : velocities;
   velocities = new List&lt;Velocity&gt;(bodyCapacity);
   velocities.setRange(0, old.length, old);
   for (int i=old.length; i&lt;velocities.length; i++) {
     velocities[i] = new Velocity();
   }
 }

 // dynamic array
 if(positions == null || bodyCapacity &gt; positions.length){
   List&lt;Position&gt; old = positions == null ?
       new List&lt;Position&gt;(0) : positions;
   positions = new List&lt;Position&gt;(bodyCapacity);
   positions.setRange(0, old.length, old);
   for (int i=old.length; i&lt;positions.length; i++) {
     positions[i] = new Position();
   }
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="report">
<button class="show-code">Code</button>
void <strong>report</strong>(List&lt;<a href="../box2d/ContactConstraint.html">ContactConstraint</a>&gt; constraints) <a class="anchor-link" href="#report"
              title="Permalink to Island.report">#</a></h4>
<div class="doc">
<pre class="source">
void report(List&lt;ContactConstraint&gt; constraints){
 if (listener == null){
   return;
 }

 for (int i = 0; i &lt; contactCount; ++i){
   Contact c = contacts[i];

   ContactConstraint cc = constraints[i];

   for (int j = 0; j &lt; cc.pointCount; ++j){
     impulse.normalImpulses[j] = cc.points[j].normalImpulse;
     impulse.tangentImpulses[j] = cc.points[j].tangentImpulse;
   }

   listener.postSolve(c, impulse);
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve">
<button class="show-code">Code</button>
void <strong>solve</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> time_step, <a href="../vector_math/vec2.html">vec2</a> gravity, bool allowSleep) <a class="anchor-link" href="#solve"
              title="Permalink to Island.solve">#</a></h4>
<div class="doc">
<pre class="source">
void solve(TimeStep time_step, vec2 gravity, bool allowSleep){
 // Integrate velocities and apply damping.
 for (int i = 0; i &lt; bodyCount; ++i){
   Body b = bodies[i];

   if (b.type != BodyType.DYNAMIC){
     continue;
   }

   final velocityDelta = new vec2(
       (b._force.x * b.invMass + gravity.x) * time_step.dt,
       (b._force.y * b.invMass + gravity.y) * time_step.dt);
   b.linearVelocity.add(velocityDelta);
   num newAngularVelocity = b.angularVelocity +
       (time_step.dt * b.invInertia * b._torque);
   b.angularVelocity = newAngularVelocity;

   num a = (1.0 - time_step.dt * b.linearDamping);
   num a1 = (0.0 &gt; (a &lt; 1.0 ? a : 1.0) ? 0.0 : (a &lt; 1.0 ? a : 1.0));
   b.linearVelocity.scale(a1);

   num a2 = (1.0 - time_step.dt * b.angularDamping);
   num b1 = (a2 &lt; 1.0 ? a2 : 1.0);
   b.angularVelocity *= 0.0 &gt; b1 ? 0.0 : b1;
 }

 // Partition contacts so that contacts with static bodies are solved last.
 int i1 = -1;
 for (int i2 = 0; i2 &lt; contactCount; ++i2) {
   Fixture fixtureA = contacts[i2].fixtureA;
   Fixture fixtureB = contacts[i2].fixtureB;
   Body bodyA = fixtureA.body;
   Body bodyB = fixtureB.body;
   bool nonStatic = bodyA.type != BodyType.STATIC &amp;&amp; bodyB.type
       != BodyType.STATIC;
   if (nonStatic){
     ++i1;
     //Swap(contacts[i1], contacts[i2]);
     Contact temp = contacts[i1];
     contacts[i1] = contacts[i2];
     contacts[i2] = temp;
   }
 }

 // Initialize velocity constraints.
 _contactSolver.init(contacts, contactCount, time_step.dtRatio);
 _contactSolver.warmStart();

 for (int i = 0; i &lt; jointCount; ++i){
   joints[i].initVelocityConstraints(time_step);
 }

 for (int i = 0; i &lt; time_step.velocityIterations; ++i) {
   for (int j = 0; j &lt; jointCount; ++j){
     joints[j].solveVelocityConstraints(time_step);
   }
   _contactSolver.solveVelocityConstraints();
 }

 // Post-solve (store impulses for warm starting).
 _contactSolver.storeImpulses();

 // Integrate positions.
 vec2 temp = new vec2.zero();
 for (int i = 0; i &lt; bodyCount; ++i){
   Body b = bodies[i];

   if (b.type == BodyType.STATIC){
     continue;
   }

   // Check for large velocities.
   _translation.copyFrom(b.linearVelocity).scale(time_step.dt);
   if (dot(_translation, _translation) &gt; Settings.MAX_TRANSLATION_SQUARED) {
     num ratio = Settings.MAX_TRANSLATION / _translation.length;
     b.linearVelocity.scale(ratio);
   }

   num rotation = time_step.dt * b.angularVelocity;
   if (rotation * rotation &gt; Settings.MAX_ROTATION_SQUARED) {
     num ratio = Settings.MAX_ROTATION / rotation.abs();
     b.angularVelocity *= ratio;
   }

   // Store positions for continuous collision.
   b.sweep.centerZero.copyFrom(b.sweep.center);
   b.sweep.angleZero = b.sweep.angle;

   // Integrate
   temp.copyFrom(b.linearVelocity).scale(time_step.dt);
   b.sweep.center.add(temp);
   b.sweep.angle += time_step.dt * b.angularVelocity;

   // Compute new transform
   b.synchronizeTransform();

   // Note: shapes are synchronized later.
 }

 // Iterate over constraints.
 for (int i = 0; i &lt; time_step.positionIterations; ++i){
   bool contactsOkay =
       _contactSolver.solvePositionConstraints(Settings.CONTACT_BAUMGARTE);

   bool jointsOkay = true;
   for (int j = 0; j &lt; jointCount; ++j){
     bool jointOkay =
         joints[j].solvePositionConstraints(Settings.CONTACT_BAUMGARTE);
     jointsOkay = jointsOkay &amp;&amp; jointOkay;
   }

   if (contactsOkay &amp;&amp; jointsOkay){
     // Exit early if the position errors are small.
     break;
   }
 }

 report(_contactSolver.constraints);


 if (allowSleep){
   num minSleepTime = Settings.BIG_NUMBER;

   num linTolSqr = Settings.LINEAR_SLEEP_TOLERANCE
       * Settings.LINEAR_SLEEP_TOLERANCE;
   num angTolSqr = Settings.ANGULAR_SLEEP_TOLERANCE
       * Settings.ANGULAR_SLEEP_TOLERANCE;

   for (int i = 0; i &lt; bodyCount; ++i){
     Body b = bodies[i];
     if (b.type == BodyType.STATIC){
       continue;
     }

     if ((b.flags &amp; Body.AUTO_SLEEP_FLAG) == 0){
       b.sleepTime = 0.0;
       minSleepTime = 0.0;
     }

     if ((b.flags &amp; Body.AUTO_SLEEP_FLAG) == 0 ||
         b.angularVelocity * b.angularVelocity &gt; angTolSqr ||
         dot(b.linearVelocity, b.linearVelocity) &gt; linTolSqr) {
       b.sleepTime = 0.0;
       minSleepTime = 0.0;
     }
     else{
       b.sleepTime += time_step.dt;
       minSleepTime = math.min(minSleepTime, b.sleepTime);
     }
   }

   if (minSleepTime &gt;= Settings.TIME_TO_SLEEP){
     for (int i = 0; i &lt; bodyCount; ++i){
       Body b = bodies[i];
       b.awake = false;
     }
   }
 }

}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
